﻿// -- MVC4WPF
// -- Copyright © 2009 Information Control Corporation
// -- Revision History:
// -- Version 0.9.0.0 First codeplex release  - Stephen Giffin

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace MVC4WPF
{
    /// <summary>
    /// Base class that implements the IWPFControllerUserControl interface, and implements the ViewContract property. 
    /// </summary>
    /// <typeparam name="VC">The view contract that this controller manages. This should always be the interface of view contract.</typeparam>
    public abstract class WPFViewUserControlControllerBase<VC> : WPFViewControllerBase<VC>, IWPFControllerUserControl where VC : IWPFViewUserControl
    {
       #region Constructor

        /// <summary>
        /// Base constructor that implements the IControllerViewBase interface
        /// </summary>
        /// <param name="viewContract">The instance of the view contract cast as the views contract interface.</param>
        protected WPFViewUserControlControllerBase(VC viewContract)
            : base(viewContract)
        {
           //Intentinally blank
        }

        #endregion

        #region Override implementation of IDisposable

        /// <summary>
        /// Disposes all managed and unmanaged resources from this class
        /// </summary>
        /// <param name="disposing">Boolean flag the determines if the managed resources are to be disposed</param>
        /// <remarks>This is not thread safe. Dispose should only be called from an owning thread.</remarks>
        protected override void Dispose(bool disposing)
        {

            //Confirming that the class has not already been disposed
            if (!this._disposed)
            {
                try
                {
                    //Determining if managed resources should be release
                    if (disposing)
                    {
                        //Releasing all managed resources
                        DisposeManagedResourcesForWPFViewUserControlControllerBase();
                    }

                    //Releasing all unmanaged resources
                    DisposeUnManagedResourcesForWPFViewUserControlControllerBase();

                }
                catch
                {
                    //Swallow dispose exceptions.
                }
                finally
                {
                    //Calling the base classes dispose
                    base.Dispose(disposing);
                }
            }

        }

        #endregion

        #region IDisposable Helper Methods

        /// <summary>
        /// Releases all managed resources from this class.
        /// </summary>
        private void DisposeManagedResourcesForWPFViewUserControlControllerBase()
        {
            try
            {
                //Intentinally blank
            }
            catch
            {
                //Swallowing exceptions during dispose.
            }
        }

        /// <summary>
        /// Releases all unmanaged instance based resources.
        /// </summary>
        private void DisposeUnManagedResourcesForWPFViewUserControlControllerBase()
        {
            try
            {
                //Intentinally blank
            }
            catch
            {
                //Swallowing exceptions during dispose.
            }
        }
        #endregion
    }
}
